import { createStore } from 'vuex'

export default createStore({
  state: {
    token:localStorage.getItem('token') || '',
    leftMenus:[],
    tabs:[],

  },
  getters: {
  },
  mutations: {
    setToken(state,token){
      localStorage.setItem('token',token);
      state.token = token;
    },
    clearToken(state){
      state.token = '';
      localStorage.removeItem('token');
    },
    getMenus(state,menus){
      state.leftMenus = menus;
    },
    getTab(state,obj){
      // state.tabs.push(obj);
      var index = state.tabs.findIndex(item=>{
        return item.name == obj.name
      })
      if(index == -1){
        state.tabs.push(obj);
      }
    },
    delTabs(state,name){
      var index = state.tabs.findIndex(item=>{
        return item.path == name;
      })
      console.log(index);
      state.tabs.splice(index,1);
    }
  },
  actions: {
  },
  modules: {
  }
})
